<template>
  <div >
    <el-table v-loading.body="listLoading" :data="list" border fit highlight-current-row style="width: 100%;">
      <el-table-column align="center" label="ID" width="80">
        <template slot-scope="scope">
          <span>{{ scope.row.id }}</span>
        </template>
      </el-table-column>

      <el-table-column width="240px" align="center" label="商户名称">
        <template slot-scope="scope">
          <span>{{ scope.row.customerName }}</span>
        </template>
      </el-table-column>

      <el-table-column width="240px" align="center" label="仓库名称">
        <template slot-scope="scope">
          <span>{{ scope.row.storageName }}</span>
        </template>
      </el-table-column>

      <!--<el-table-column width="120px" align="center" label="仓库简称">
        <template slot-scope="scope">
          <span>{{ scope.row.shortName }}</span>
        </template>
      </el-table-column>-->


      <el-table-column class-name="status-col" label="状态" width="100px">
        <template slot-scope="scope">
          <el-tag>{{ scope.row.status| statusFilter }}</el-tag>
        </template>
      </el-table-column>

      <el-table-column width="240px" align="center" label="创建日期">
        <template slot-scope="scope">
          <span>{{ scope.row.createTime }}</span>
        </template>
      </el-table-column>

      <el-table-column align="center" label="操作" width="280px">
        <template slot-scope="scope">
          <router-link :to="'/storagemain/storagelist/detail?id='+scope.row.id">
            <el-button type="primary" size="small" icon="el-icon-edit">详情</el-button>
          </router-link>
          <router-link :to="'/storagemain/storagelist/storageedit?id='+scope.row.id">
            <el-button type="primary" size="small" icon="el-icon-edit">编辑</el-button>
          </router-link>
          <el-button type="primary" size="small" @click ="deleteStorage(scope.row.id)" icon="el-icon-delete">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <div class="pagination-container">
      <el-pagination
        :current-page="listQuery.page"
        :page-sizes="[10,20,30, 50]"
        :page-size="listQuery.limit"
        :total="total"
        background
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"/>
    </div>

  </div>
</template>

<script>
import { fetchList, deleteStorage } from '@/api/storage'

export default {
  name: 'Storagelist',
  filters: {
    statusFilter(status) {
      const statusMap = {
        1: '是',
        0: '否',
        2: '否'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      list: null,
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 10,
        uissssd: 1269,
        status: 0
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      console.log(this.listQuery)
      this.listLoading = true
      fetchList(this.listQuery).then(response => {
        this.list = response.data.data
        this.total = response.data.count
        this.listLoading = false
      })
    },
    handleSizeChange(val) {
      this.listQuery.limit = val
      this.getList()
    },
    handleCurrentChange(val) {
      //console.log(val)
      this.listQuery.page = val
      this.getList()
    },
    deleteStorage(id){
      this.$confirm('演示作用，(此操作将永久删除该仓库, 是否继续?)', '演示删除', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        // deleteStorage({"ids":id}).then(response => {
        //   this.listLoading = false
        // })

        this.$message({
          type: 'success',
          message: '删除成功!'
        });
        this.getList()
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });


    }
  }
}
</script>

<style scoped>
.edit-input {
  padding-right: 100px;
}
.cancel-btn {
  position: absolute;
  right: 15px;
  top: 10px;
}
</style>
